<?php

/**
 * This is the model class for table "cierre_estudiante".
 *
 * The followings are the available columns in table 'cierre_estudiante':
 * @property integer $id
 * @property string $code
 * @property integer $carnet
 * @property string $nombre
 * @property string $sede
 * @property string $fecha_cierre
 * @property integer $id_code
 * @property integer $carrera
 */
class cierre_estudiante extends CActiveRecord
{
    public $Cierrecarrera;
    public $Cierrecodigo;
	/**
	 * Returns the static model of the specified AR class.
	 * @return cierre_estudiante the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'cierre_estudiante';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('carnet, code', 'required'),
			array('carnet,id_code', 'numerical', 'integerOnly'=>true),
			array('code', 'length', 'max'=>30),
			array('nombre', 'length', 'max'=>120),
			array('sede', 'length', 'max'=>300),
			array('fecha_cierre', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, Cierrecodigo, carnet, nombre, sede, fecha_cierre, Cierrecarrera', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
                    'cierre' => array(self::BELONGS_TO, 'cierre', 'id_code'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'Id',
			'code' => 'Code',
			'carnet' => 'Carnet',
			'nombre' => 'Nombre',
			'sede' => 'Sede',
			'fecha_cierre' => 'Fecha Cierre',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;
                $criteria->with = array('cierre');
		$criteria->compare('id',$this->id);

		$criteria->compare('cierre.code',$this->Cierrecodigo,true);

		$criteria->compare('carnet',$this->carnet);

		$criteria->compare('nombre',$this->nombre,true);

		$criteria->compare('sede',$this->sede,true);

		$criteria->compare('fecha_cierre',$this->fecha_cierre,true);
                
                $criteria->compare('cierre.carrera',$this->Cierrecarrera,true);
                

		return new CActiveDataProvider('cierre_estudiante', array(
			'criteria'=>$criteria,
                        'sort'=>array(
                        'attributes'=>array(
                               'Cierrecodigo'=>array(
                                    'asc'=>'cierre.code',
                                    'desc'=>'cierre.code DESC',
                                ),
                                'Cierrecarrera'=>array(
                                    'asc'=>'cierre.carrera',
                                    'desc'=>'cierre.carrera DESC',
                                ),
                                '*',
                            ),
                        ),
		));
	}
}